package com.bh.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.enums.BusinessType;
import com.bh.order.domain.JcPresco;
import com.bh.order.service.IJcPrescoService;
import com.bh.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import com.bh.common.core.page.TableDataInfo;

/**
 * 客户预录单Controller
 * 
 * @author slx
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/order/presco")
public class JcPrescoController extends BaseController
{
    @Autowired
    private IJcPrescoService jcPrescoService;

    /**
     * 查询客户预录单列表
     */
    @ApiOperation("查询客户预录单列表")
    @PreAuthorize("@ss.hasPermi('order:presco:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcPresco jcPresco)
    {
        startPage();
        List<JcPresco> list = jcPrescoService.selectJcPrescoList(jcPresco);
        return getDataTable(list);
    }

    /**
     * 导出客户预录单列表
     */
    @PreAuthorize("@ss.hasPermi('order:presco:export')")
    @Log(title = "客户预录单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcPresco jcPresco)
    {
        List<JcPresco> list = jcPrescoService.selectJcPrescoList(jcPresco);
        ExcelUtil<JcPresco> util = new ExcelUtil<JcPresco>(JcPresco.class);
        util.exportExcel(response, list, "客户预录单数据");
    }

    /**
     * 获取客户预录单详细信息
     */
    @ApiOperation("获取客户预录单详细信息")
    @PreAuthorize("@ss.hasPermi('order:presco:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcPrescoService.selectJcPrescoById(id));
    }

    /**
     * 新增客户预录单
     */
    @ApiOperation("新增客户预录单")
    @PreAuthorize("@ss.hasPermi('order:presco:add')")
    @Log(title = "客户预录单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcPresco jcPresco)
    {
        return toAjax(jcPrescoService.insertJcPresco(jcPresco));
    }

    /**
     * 修改客户预录单
     */
    @ApiOperation("修改客户预录单")
    @PreAuthorize("@ss.hasPermi('order:presco:edit')")
    @Log(title = "客户预录单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcPresco jcPresco)
    {
        return toAjax(jcPrescoService.updateJcPresco(jcPresco));
    }

    /**
     * 删除客户预录单
     */
    @ApiOperation("删除客户预录单")
    @PreAuthorize("@ss.hasPermi('order:presco:remove')")
    @Log(title = "客户预录单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcPrescoService.deleteJcPrescoByIds(ids));
    }

    /**
     * confirmationOrder
     */
    @ApiOperation("确认订单")
    @PreAuthorize("@ss.hasPermi('order:presco:confirm')")
    @Log(title = "客户预录单", businessType = BusinessType.UPDATE)
    @PutMapping("/confirmationOrder/{prescoId}")
    public AjaxResult confirmationOrder(@PathVariable("prescoId") Long prescoId)
    {
        JcPresco jcPresco = jcPrescoService.selectJcPrescoById(prescoId);
        if (jcPresco.getStatus() != 1) {
            return error("预录单状态不能确认！");
        }
        return toAjax(jcPrescoService.confirmationOrder(jcPresco));
    }
}
